import { Component } from "react";
import { TabBar } from "antd-mobile";
import tabbarList from "./lib/tabbarList";
import { withRouter } from "react-router-dom";

const tabs = tabbarList();
class RTabBar extends Component {
  state = { pathname: this.props.location.pathname };

  setRouteActive = (value) => {
    this.setState(() => ({ pathname: value }));
    this.props.history.push(value);
  };

  render() {
    return (
      <TabBar activeKey={this.state.pathname} onChange={this.setRouteActive}>
        {tabs.map((item) => (
          <TabBar.Item key={item.key} icon={item.icon} title={item.title} />
        ))}
      </TabBar>
    );
  }
}

export default withRouter(RTabBar);
